﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.Serialization;
//using System.ServiceModel;
//using System.ServiceModel.Web;

namespace DataService.Model
{
    [DataContract (IsReference=true)]
    public class User : Utilities
    {
        private string _userName;
        private string _passWord;
        private int _pkID = 0;

        [DataMember]
        public string Username 
        {
            get 
            {
                return _userName;
            }
            set 
            {
                _userName = value;
            }
        }//end username field

        [DataMember]
        public string Password
        {
            get
            {
                return _passWord;
            }
            set
            {
                _passWord = value;
            }
        }//end password

        [DataMember]
        public int PKID
        {
            get
            {
                return _pkID;
            }
            private set
            {
                _pkID = value;
            }
        }//end PKID
        //constructor with parameters

        public User(string UserName, string Password)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@Username", Username),
                new SqlParameter("@Password", Password)
            };
            DataTable dt = ReadData("spLogin", parameters);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    PKID = Convert.ToInt32(r["pkID"].ToString());
                    this.Username = r["Username"].ToString();
                    this.Password = r["Password"].ToString();
                }
            }
            else
                _pkID = 0;
        }

        //no args constructor
        public User()
        {
            User user = new User();
            // TODO: Complete member initialization
        }
    }
}




